home *** CD-ROM | disk | FTP | other *** search
/ Die Speccy' 97 / Die Speccy' 97.iso / amiga_system / the_aminet / util / cli / dfree.lha / dfree.c < prev    next >
C/C++ Source or Header  |  1994-10-13  |  3KB  |  111 lines

  1. /****************************************************************************/
  2. /*   dfree v1.0   Show free space on a disk - Shell command                 */
  3. /*                                                                          */
  4. /*   USAGE: dfree <device/name>                                             */
  5. /*                                                                          */
  6. /*   Max Francis                                    started: 12/02/1994     */
  7. /****************************************************************************/
  8.  
  9. #include <dos/dos.h>
  10. #include <stdio.h>
  11.  
  12. void main( int argc, char *argv[] );
  13. void helpscreen( void );
  14. void cleanup( void );
  15.  
  16. struct InfoData *infodata_p;
  17. struct InfoData infodata;
  18. BPTR lock_p;
  19.  
  20. /* Formatted version string for the 2.0 VERSION command */ 
  21. UBYTE *vers = "\0$VER: MF DFree v1.0 (12/02/94)";
  22.  
  23.  
  24. void main( int argc, char *argv[] )
  25. {
  26.         BOOL success;
  27.         LONG disk_blocks;
  28.         LONG used_blocks;
  29.         LONG block_bytes;
  30.         LONG disk_type;
  31.         LONG free_space;
  32.         int c;
  33.  
  34.         if( argc != 2) 
  35.                 helpscreen();
  36.         if( strcmp("?",argv[1]) == 0 )
  37.                 helpscreen();
  38.         if( strcmp("help",argv[1]) == 0 )
  39.                 helpscreen();
  40.         if( strcmp("HELP",argv[1]) == 0 )
  41.                 helpscreen();
  42.  
  43.         /* Convert user's device to upper case (just coz it looks nice) */
  44.         for(c=0; c <= strlen(argv[1]); c++)
  45.                 argv[1][c] = toupper(argv[1][c]);
  46.  
  47.         /* Attempt to lock the device/disk */
  48.         lock_p = Lock( argv[1], ACCESS_READ );
  49.  
  50.         if( lock_p == NULL )
  51.         {
  52.                 printf("Can't examine %s\n", argv[1] );
  53.                 cleanup();
  54.         }
  55.  
  56.         /* Get the Information block (struct InfoData) of the device */
  57.         /* First, point the pointer to the structure... */
  58.         infodata_p = &infodata;
  59.         success = Info( lock_p, infodata_p );
  60.         if( !success )
  61.         {
  62.                 printf("Can't examine %s\n", argv[1] );
  63.                 cleanup();
  64.         }
  65.  
  66.         disk_blocks = infodata_p->id_NumBlocks;
  67.         used_blocks = infodata_p->id_NumBlocksUsed;
  68.         block_bytes = infodata_p->id_BytesPerBlock;
  69.         disk_type   = infodata_p->id_DiskType;
  70.  
  71.         free_space = (disk_blocks - used_blocks) * block_bytes;
  72.  
  73.         if( free_space > (5*1048576) )
  74.                 printf("%s %dM free\n", argv[1], free_space/1048576);
  75.         else
  76.                 if( free_space == 1)
  77.                         printf("%s %d byte free\n", argv[1], free_space);
  78.                 else
  79.                         if( free_space < 1024)
  80.                                 printf("%s %d bytes free\n", argv[1], free_space);
  81.                         else
  82.                                 printf("%s %dK free\n", argv[1], free_space/1024);
  83.  
  84.         cleanup();
  85. }
  86.  
  87.  
  88.  
  89.  
  90. void helpscreen( void )
  91. {
  92.         printf("MF \"dfree\"\nUSAGE: dfree <DEVICE/DISK>\n");
  93.         printf("Show free disk space on DEVICE or DISK specified\n");
  94.         printf("Eg. \"dfree df0:\"\n");
  95.         cleanup();
  96. }
  97.  
  98.  
  99.  
  100. void cleanup( void )
  101. {
  102.         if( lock_p )  /* 'spose we'd better unlock the directory */
  103.         {
  104.                 UnLock( lock_p );
  105.         }
  106.         exit( 0 );
  107.  
  108. }
  109.  
  110.  
  111.